package com.oracle.cmp.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/index.do")
public class IndexController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得cookie数据，启动获得username、password、rememberMe值
        //转发给login.jsp
        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if ("loginname".equals(cookie.getName())) {
                    req.setAttribute("loginname", cookie.getValue());
                }
                if ("loginpwd".equals(cookie.getName())) {
                    req.setAttribute("loginpwd", cookie.getValue());
                }
                if ("rember".equals(cookie.getName())) {
                    req.setAttribute("rember", cookie.getValue());
                }
//                if ("identy".equals(cookie.getName())){
//                    req.setAttribute("identy",cookie.getValue());
//                }
            }
        }
        req.getRequestDispatcher("/login.jsp").forward(req, resp);
    }
}





